# -*- coding:utf-8 -*-
import json
import requests


_SEND_TEXT_API = 'https://api.potato.im:8443/8025178:EPl15VKEjL0FxOx0amOH3ga6/sendTextMessage'
_SEND_INLINE_API = 'https://api.potato.im:8443/8025178:EPl15VKEjL0FxOx0amOH3ga6/sendTextMessage'
_SEND_ACK_API = 'https://api.potato.im:8443/8025178:EPl15VKEjL0FxOx0amOH3ga6/answerCallbackQuery'


def send_callback_ack(user_id, inline_message_id, show_alert=False):
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
    post_data = {
        "inline_message_id": inline_message_id,
        "show_alert": show_alert,
    }
    response = requests.post(_SEND_ACK_API, data=json.dumps(post_data,separators=(',',':')), headers=headers, timeout=5)
    print response.text


def send_text_msg(chat_type, chat_id, chat_text):
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
    post_data = {
        "chat_type": chat_type,
        "chat_id": chat_id,
        "text": chat_text,
        "markdown": True,
    }
    response = requests.post(_SEND_TEXT_API, data=json.dumps(post_data,separators=(',',':')), headers=headers, timeout=5)
    print response.text


def send_inline_markup_msg(chat_type, chat_id, chat_text, inline_markup):
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
    post_data = {
        "chat_type": chat_type,
        "chat_id": chat_id,
        "text": chat_text,
        "markdown": True,
        "reply_markup": {
            "type": 4,
            "inline_keyboard": inline_markup
        }
    }
    print json.dumps(post_data)
    response = requests.post(_SEND_INLINE_API, data=json.dumps(post_data,separators=(',',':')), headers=headers, timeout=5)
    print response.text


if __name__ == "__main__":
    inline_markup = [
        [{
            'type': 0,
            'text': 'Hello',
            'data': 'OnClick'
        }]
    ]
    send_inline_markup_msg(1, 8001739, u'start', inline_markup)
    #send_text_msg(1, 8001739, u'this is a plain text msg')
